*     euclid.f (FORTRAN 77)
*     Find greatest common divisor using the Euclidean algorithm

      PROGRAM EUCLID
         PRINT *, 'A?'
         READ *, NA
         IF (NA.LE.0) THEN
            PRINT *, 'A must be a positive integer.'
            STOP
         END IF
         PRINT *, 'B?'
         READ *, NB
         IF (NB.LE.0) THEN
            PRINT *, 'B must be a positive integer.'
            STOP
         END IF
         PRINT *, 'The GCD of', NA, ' and', NB, ' is', NGCD(NA, NB), '.'
         STOP
      END

      FUNCTION NGCD(NA, NB)
         IA = NA
         IB = NB
    1    IF (IB.NE.0) THEN
            ITEMP = IA
            IA = IB
            IB = MOD(ITEMP, IB)
            GOTO 1
         END IF
         NGCD = IA
         RETURN
      END
